package com.webchat.user.controller;

import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.domain.vo.request.payment.CreateAppRequestVO;
import com.webchat.domain.vo.response.payment.AppBaseResponseVO;
import com.webchat.domain.vo.response.payment.CreateAppResponseVO;
import com.webchat.rmi.user.AccessApplicationServiceClient;
import com.webchat.user.service.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class AccessApplicationServiceController implements AccessApplicationServiceClient {


    @Autowired
    private ApplicationService accessApplicationService;

    @Override
    public APIResponseBean<Boolean> checkAkSk(String ak, String sk) {
        boolean checkResult = accessApplicationService.validateAccessApplicationAkSk(ak, sk);
        return APIResponseBeanUtil.success(checkResult);
    }

    @Override
    public APIResponseBean<CreateAppResponseVO> createApp(@RequestBody CreateAppRequestVO createAppRequest) {
        // TODO
        CreateAppResponseVO app = accessApplicationService.saveApp(createAppRequest);
        return APIResponseBeanUtil.success(app);
    }

    @Override
    public APIResponseBean<Boolean> publishApp(@PathVariable Long appId) {
        accessApplicationService.publishApp(appId);
        return APIResponseBeanUtil.success(true);
    }

    @Override
    public APIResponseBean<Boolean> deleteApp(@PathVariable Long appId) {
        accessApplicationService.deleteApp(appId);
        return APIResponseBeanUtil.success(true);
    }

    @Override
    public APIPageResponseBean<AppBaseResponseVO> page(String keywords, Integer pageNo, Integer pageSize) {

        return accessApplicationService.page(keywords, pageNo, pageSize);
    }
}
